package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduChapter;
import com.atguigu.eduservice.entity.chapter.ChapterVo;
import com.atguigu.eduservice.service.EduChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author thomasyang
 * @since 2023-12-09
 */


//@CrossOrigin
@RestController
@RequestMapping("/eduservice/chapter")
public class EduChapterController {

    @Autowired
    private EduChapterService chapterService;

    //课程大纲列表,根据课程id进行查询
    @ApiOperation(value = "课程id进行查询课程大纲列表")
    @GetMapping("getChapterVideo/{courseId}")
    private R getChapterVideo(@PathVariable String courseId){

        List<ChapterVo> eduChapterList = chapterService.getChapterVideoById(courseId);

        return R.ok().data(eduChapterList);
    }

    @ApiOperation(value = "添加章节")
    @PostMapping("addChapter")
    public R addChapter(@RequestBody EduChapter  eduChapter){

        boolean save = chapterService.save(eduChapter);

        return  R.ok();
    }
    //根据更新章节
    @ApiOperation(value = "更新章节")
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter){

        boolean update = chapterService.updateById(eduChapter);

        return R.ok();
    }


    //根据章节id查询
    @ApiOperation(value = "根据id进行查询课程")
    @GetMapping("/getChapter/{id}")
    private R getChapterById(@PathVariable String id){

        EduChapter chapter = chapterService.getById(id);

        return R.ok().data(chapter);
    }

    //根据删除章节
    @ApiOperation(value = "删除章节")
    @DeleteMapping("/delete/{id}")
    public R removeChapterById(@PathVariable String id){

        boolean remove = chapterService.removeChapterById(id);

        return  R.flagCheck(remove);
    }



}

